{include file="public/header"}
</head>
<body>
	<header>
		<div>
			<a href="javascript:history.back();"><i class="icon-fanhui icon iconfont"></i></a>
		</div>
		<div>
			收货地址
		</div>
		<div></div>
	</header>
	<div class="main vip">
		
		<div class="tabs">
			<a href="../user/user.html">我的订单</a>
			<a href="address.html" class="active">收货地址</a>
		</div>
		
		<div class="tabContent">
			<div class="addrDetail">
				<div class="tip">
					您已保存了{$count}个常用地址，最多可以保存5个
				</div>
				{foreach $list as $v}
				<div class="adr" aid="{$v['id']}">
					<h1>
						{$v['name']}
						{if $v['is_default']==1}
						<span class="default">默认地址</span>
						{/if}
					</h1>
					<span class="takeP">
						收货人：<span>{$v['name']}</span>
					</span>
					<span class="takeAdr">
						地址：<span>{$v['asheng']} {$v['acity']} {$v['aquyu']}</span>
					</span>
					<span class="sprice">
						电话：<span>{$v['tel']}</span>
					</span>
					<span class="editC">
						{if $v['is_default']==0}
						<a href='' class='setDefault'>设为默认</a>
						{/if}
						<a href="{:url('Address/addressEdit',['id'=>$v['id']])}" class="edit">编辑</a>
						<a href="#" class="del">删除</a>
					</span>
				</div>
				{/foreach}
				<a href="#" count="{$count}" class="addAddr">添加收货地址</a>
			</div>	
		</div>	
	</div>
	<script>
		//删除
		$('.del').click(function () {
            var aid=$(this).parent().parent().attr("aid");
            $.ajax({
                type: 'post',
                url: '{:url("Address/addressDel")}',
                data: {id:aid},
                dataType: 'json',
                success: function (data) {
                    window.location.reload();
                }
            });
        })
		//判断是否可以添加
		$('.addAddr').click(function () {
			var count = $(this).attr('count');
			if(count>=5){
			    alert('最多添加五个地址');
			}else {
			    location.href="addressAdd";
			}
        })
		//默认地址
		$('.setDefault').click(function () {
            var aid=$(this).parent().parent().attr("aid");
            $.ajax({
                type: 'post',
                url: '{:url("Address/ajaxisDefault")}',
                data: {id:aid},
                dataType: 'json',
                success: function (data) {

                }
            });
        })
	</script>
	{include file="public/footer"}
</body>
</html>